package xyz.yudan.app.dao.biz;

import xyz.yudan.app.dao.base.BaseTeam;
import xyz.yudan.app.dao.base.BaseUser;
import xyz.yudan.app.relation.UserTeamRelation;

import java.util.ArrayList;
import java.util.Collections;

/**
 * Created by gamy on 2018/4/6.
 */
public class BizTeam extends BaseTeam {

    private BaseUser creator = null;
    private ArrayList<BaseUser> managers = null;
    private ArrayList<BaseUser> members = null;
    private int relation = UserTeamRelation.NONE; //当前用户与团队的关系

    public BizTeam(BaseTeam team) {
        super(team);
    }

    public BaseUser getCreator() {
        return creator;
    }

    public void setCreator(BaseUser creator) {
        this.creator = creator;
    }

    public ArrayList<BaseUser> getManagers() {
        return managers;
    }

    public void setManagers(ArrayList<BaseUser> managers) {
        this.managers = managers;
    }

    public ArrayList<BaseUser> getMembers() {
        return members;
    }

    public void setMembers(ArrayList<BaseUser> members) {
        this.members = members;
    }

    public int getRelation() {
        return relation;
    }

    public void setRelation(int relation) {
        this.relation = relation;
    }

    public static int calRelation(BizTeam team, String userId) {
        if (userId == null) {
            return UserTeamRelation.NONE;
        }

        if (team.getCreatorUid() != null && team.getCreatorUid().equalsIgnoreCase(userId)
                || team.getManagerUids() != null && team.getManagerUids().contains(userId)) {
            return UserTeamRelation.MANAGER_RELATION;
        }

        if (team.getMemberUids() != null && team.getMemberUids().contains(userId)) {
            return UserTeamRelation.MEMBER_RELATION;
        }

        return UserTeamRelation.NONE;
    }
}
